package ObjectClass;

/**
 *
 * @author Jeppe
 */
public class Task {

    private int taskID;
    private int dd;
    private int mm;
    private int YYYY;
    private String description;
    private String cargoType;
    private int cargoWeight;
    private int cargoNumber;
    private boolean dangCargo;
    private Cargo cargo;
    private Driver driver;
    private Customer customer;
    private Address pickUpAddress;
    private Address deliveryAddress;
    private Distance distance;
    private Vehicle vehicle;

    public Task(int taskID, int dd, int mm, int YYYY, String description, String cargoType, int cargoWeight, int cargoNumber, boolean dangCargo, Cargo cargo, Driver driver, Customer customer, Address pickUpAddress, Address deliveryAddress, Distance distance, Vehicle vehicle) {
        this.taskID = taskID;
        this.dd = dd;
        this.mm = mm;
        this.YYYY = YYYY;
        this.description = description;
        this.cargoType = cargoType;
        this.cargoWeight = cargoWeight;
        this.cargoNumber = cargoNumber;
        this.dangCargo = dangCargo;
        this.cargo = cargo;
        this.driver = driver;
        this.customer = customer;
        this.pickUpAddress = pickUpAddress;
        this.deliveryAddress = deliveryAddress;
        this.distance = distance;
        this.vehicle = vehicle;
    }

    public Task(int dd, int mm, int YYYY, String description, String cargoType, int cargoWeight, int cargoNumber, boolean dangCargo, Cargo cargo, Driver driver, Customer customer, Address pickUpAddress, Address deliveryAddress, Distance distance, Vehicle vehicle) {
        this.dd = dd;
        this.mm = mm;
        this.YYYY = YYYY;
        this.description = description;
        this.cargoType = cargoType;
        this.cargoWeight = cargoWeight;
        this.cargoNumber = cargoNumber;
        this.dangCargo = dangCargo;
        this.cargo = cargo;
        this.driver = driver;
        this.customer = customer;
        this.pickUpAddress = pickUpAddress;
        this.deliveryAddress = deliveryAddress;
        this.distance = distance;
        this.vehicle = vehicle;
    }

    public Task() {
        dangCargo = false;
    }

    
    // <editor-fold defaultstate="collapsed" desc="Get-metoder">
    public int getTaskID() {
        return taskID;
    }

    public int getDD() {
        return dd;
    }

    public int getMM() {
        return mm;
    }

    public int getYYYY() {
        return YYYY;
    }

    public String getDescription() {
        return description;
    }

    public String getCargoType() {
        return cargoType;
    }

    public int getCargoWeight() {
        return cargoWeight;
    }

    public int getCargoNumber() {
        return cargoNumber;
    }
    
    public String getCargoNumberString() {
        String unit = "";
        if (cargoType.equals("pallet")) {
            unit = "Paller";
        } else if (cargoType.equals("cargo") || cargoType.equals("special")) {
            unit = "m³";
        }

        return cargoNumber + " " + unit;
    }

    public boolean getDangCargo() {
        return dangCargo;
    }

    public Cargo getCargo() {
        return cargo;
    }

    public Driver getDriver() {
        return driver;
    }

    public Customer getCustomer() {
        return customer;
    }

    public Address getPickUpAddress() {
        return pickUpAddress;
    }

    public Address getDeliveryAddress() {
        return deliveryAddress;
    }

    public Distance getDistance() {
        return distance;
    }

    public Vehicle getVehicle() {
        return vehicle;
    }
    /**
     * Anvender en boolean (dangCargo), et distance og et cargo- objekt til at udregne prisen. Derfor forudsættes at ingen af disse er null da metoden derfor ikke vil kunne beregne pris..
     * @return 
     */
    public String getPrice() {
        double totalPrice = distance.getDistance() * cargo.price;
        if (dangCargo) {
            totalPrice = totalPrice + ((totalPrice / 100) * 10);
        }
        return totalPrice + " Kr";
    }

    // </editor-fold> 
    
    // <editor-fold defaultstate="collapsed" desc="Set-metoder">
    public void setDd(int dd) {
        this.dd = dd;
    }

    public void setMm(int mm) {
        this.mm = mm;
    }

    public void setYYYY(int YYYY) {
        this.YYYY = YYYY;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setCargoType(String cargoType) {
        this.cargoType = cargoType;
    }

    public void setCargoWeight(int cargoWeight) {
        this.cargoWeight = cargoWeight;
    }

    public void setCargoNumber(int cargoNumber) {
        this.cargoNumber = cargoNumber;
    }

    public void setDangCargo(boolean dangCargo) {
        this.dangCargo = dangCargo;
    }

    public void setCargo(Cargo cargo) {
        this.cargo = cargo;
        System.out.println("Sætter cargo");
    }

    public void setDriver(Driver driver) {
        this.driver = driver;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public void setPickUpAddress(Address pickUpAddress) {
        this.pickUpAddress = pickUpAddress;
    }

    public void setDeliveryAddress(Address deliveryAddress) {
        this.deliveryAddress = deliveryAddress;
    }

    public void setDistance(Distance distance) {
        this.distance = distance;
    }

    public void setVehicle(Vehicle vehicle) {
        this.vehicle = vehicle;
    }
// </editor-fold>

    @Override
    public String toString() {
        return dd + "/" + mm + "-" + YYYY; //customer.getCompanyName()
    }

    public String toStringInfo() {
        String info;
        info = "Dato: " + dd + "/" + mm + "-" + YYYY
                + "\nBeskrivelse: " + description
                + "\nFragtpris: " + getPrice()
                + "\nAntal: " + getCargoNumberString()
                + "\nChauffør: " + driver.toString()
                + "\nKunde: " + customer.toString() + "\n"
                + "\nAfhentningsadresse: \n" + pickUpAddress.toString() + "\n"
                + "\nLeveringsaddresse: \n" + deliveryAddress.toString() + "\n"
                + "\nDistance: " + distance.getDistance()
                + "\nKøretøj: " + vehicle.getLicensePlate();
        return info;
    }

    public String toStringSQL() {
        int dangCargoSQL = 0;
        if(dangCargo){
            dangCargoSQL = 1;
        }
        return "(" + dd + ", " + mm + ", " + YYYY +", '" + description+ "', '"+cargoType+"', "+cargoWeight+", "+cargoNumber+", "+dangCargoSQL + ", " + cargo.getID() + ", " + driver.getPhoneNo() + ", " + customer.getPhoneNo() + ", " + pickUpAddress.getID() + ", " + deliveryAddress.getID() + ", " + distance.getID() + ", '" + vehicle.getLicensePlate() + "')";
    }
}